package com.lili.member.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.member.bean.Member;
import com.lili.member.mapper.MemberMapper;
import com.lili.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberMapper memberMapper;
    @Override
    public int save(Member member) {
        return memberMapper.insert(member);
    }

    @Override
    public Page<Member> queryByPage(int current, int pageSize, Map map) {
        Page<Member> page=new Page<>(current,pageSize);
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        String nickName = (String) map.get("nickName");
        if (!StringUtils.isEmpty(nickName)) {
            wrapper.eq("nick_name",nickName);
        }
        String mobile = (String) map.get("mobile");
        if (!StringUtils.isEmpty(mobile)) {
            wrapper.eq("mobile",mobile);
        }
        String username= (String) map.get("username");
        if (!StringUtils.isEmpty(username)) {
            wrapper.eq("username",username);
        }
        memberMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public int update(Member member) {
        return memberMapper.updateById(member);
    }


    @Override
    public int updateState(String id) {
        return memberMapper.updateState(id);
    }

    @Override
    public int updateStateRestart(String id) {
        return memberMapper.updateStateRestart(id);
    }


}
